/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cryptography;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import platform.TenorCryptoUtils;
import zorg.CryptoException;
import zorg.platform.HMAC;

/**
 *
 * @author Tomasz Nowak
 */
public class HmacSHA1 implements HMAC
{
	MessageDigest digest;
	byte[] key;

	public HmacSHA1( byte[] hmacKey ) throws NoSuchAlgorithmException
	{
		digest = MessageDigest.getInstance("SHA-1");
		key = hmacKey;
	}

	@Override
	public void reset() throws CryptoException
	{
		digest.reset();
	}

	@Override
	public void update( byte[] data, int offset, int length )
	{
		digest.update(TenorCryptoUtils.subArray(data, offset, length));
	}

	@Override
	public void update( byte[] data ) throws CryptoException
	{
		digest.update(data);
	}

	@Override
	public int getMAC( byte[] data, int offset ) throws CryptoException
	{
		byte[] result = digest.digest();
		for ( int i = 0; i < result.length; ++i )
		{
			data[i + offset] = result[i];
		}
		return 0;
	}
}
